<?php
exit();
/*替會員、代理商、總代理和股東加上其所有階層ID*/
include($_SERVER["DOCUMENT_ROOT"]."/db.inc.php");
include($_SERVER["DOCUMENT_ROOT"]."/common/SysParam.inc.php");

$flScale = round(100 - $_KSysParam[CompanyMinScale]) / 100;

//新增臨時總監
$strSQL = "insert into `bet_Member`(Account, Name, Password, MemberGroup, CreditLine, isAllAccount, Scale) values('DrCom', 'DrCom', 'uuss@taiwain', '5', '10000000000', '1', '".$flScale."')";
if(!PMA_mysql_query($strSQL, $_ConnMaster)){
	exit("Error".PMA_mysql_error($_ConnMaster));
}
$intDID = mysql_insert_id($_ConnMaster);
$strSQL = "insert into `bet_MemberLimit`(MemID, Bet_Type, LimitType, LimitValue) select '".$intDID."', Bet_Type, LimitType, LimitValue from `bet_MemberLimit` where MemID = 5";
if(!PMA_mysql_query($strSQL, $_ConnMaster)){
	exit("Error".PMA_mysql_error($_ConnMaster));
}
$strSQL = "select ID, A_Commission_MinValue as ALine, B_Commission_MinValue as BLine, C_Commission_MinValue as CLine from `bet_BetType` where LottoID = 1";
if(!$RS = PMA_mysql_query($strSQL, $_ConnMaster)){
	exit( PMA_mysql_error($_ConnMaster));
}
while($Rows = PMA_mysql_fetch_object($RS)){
	$arrSQL[0] = "insert into `bet_Commission`(MemID, Bet_Type, Gamble_Type, Commission) values('".$intDID."', '".$Rows -> ID."', '1', '".$Rows -> ALine."')";
	$arrSQL[1] = "insert into `bet_Commission`(MemID, Bet_Type, Gamble_Type, Commission) values('".$intDID."', '".$Rows -> ID."', '2', '".$Rows -> ALine."')";
	$arrSQL[2] = "insert into `bet_Commission`(MemID, Bet_Type, Gamble_Type, Commission) values('".$intDID."', '".$Rows -> ID."', '3', '".$Rows -> ALine."')";
	foreach($arrSQL as $strSQL){
		if(!PMA_mysql_query($strSQL, $_ConnMaster)){
			exit("Error".PMA_mysql_error($_ConnMaster));
		}	
	}
}

$strSQL = "update `bet_Member` set ParentID = ".$intDID." where MemberGroup = 4";
if(!PMA_mysql_query($strSQL, $_ConnMaster)){
	exit("Error".PMA_mysql_error($_ConnMaster));
}
$strSQL = "update `bet_BetList` set DirectorID = ".$intDID." where 1";
if(!PMA_mysql_query($strSQL, $_ConnMaster)){
	exit("Error".PMA_mysql_error($_ConnMaster));
}

for($i = 5; $i > 1; $i--){
	$strSQL = "select ID, MemberGroup, SubID, MainID, StockID, DirectorID from `bet_Member` where MemberGroup = ".$i;
	if(!$RS = PMA_mysql_query($strSQL, $_ConnMaster)){
		exit( PMA_mysql_error($_ConnMaster));
	}

	while($Rows = PMA_mysql_fetch_object($RS)){
		$strSQL = "";
		switch($Rows -> MemberGroup){
			case 5:
				$strSQL = "DirectorID = ".$Rows -> ID;
				break;
			
			case 4:
				$strSQL = "DirectorID = ".$Rows -> DirectorID.", StockID = ".$Rows -> ID;
				break;

			case 3:
				$strSQL = "DirectorID = ".$Rows -> DirectorID.", StockID = ".$Rows -> StockID.", MainID = ".$Rows -> ID;
				break;

			case 2:
				$strSQL = "DirectorID = ".$Rows -> DirectorID.", StockID = ".$Rows -> StockID.", MainID = ".$Rows -> MainID.", SubID = ".$Rows -> ID;
				break;
		}
		$strSQL = "update `bet_Member` set ".$strSQL." where ParentID = ".$Rows -> ID;
		if(!PMA_mysql_query($strSQL, $_ConnMaster)){
			exit(PMA_mysql_error($_ConnMaster)."\nSQL:".$strSQL);
		}else{
			print $Rows -> MemberGroup." OK! <br />\n";
		}
	}
}
?>